﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebSocketCore.Domain;
using WebSocketCore.Domain.Impl;

namespace WebSocketCore.Controllers
{
    public class HomeController : Controller
    {
        protected IUserManager _userManager;
        protected IChatRoomManager _chatRoomManager;
        public HomeController(IUserManager userManager, IChatRoomManager chatRoomManager)
        {
            this._userManager = userManager;
            this._chatRoomManager = chatRoomManager;
        }
        [HttpGet] 
        public IActionResult Index()
        {
            ViewBag.ShowMsg = false;
            return View();
        }
        [HttpPost]
        public IActionResult Index(string username)
        {
            //TODO 登陆
            var user= _userManager.CheckUser(username, "");
            if (user!=null)
            {
                HttpContext.Session.Set("User", user.Id);
                return Redirect("/home/websocket");
            }
            ViewBag.ShowMsg = true;
            return View();
        }
        public IActionResult WebSocket()
        {
            ViewBag.ChatRooms = _chatRoomManager.GetRooms();
            return View();
        }
        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View();
        }
    }
}
